<template>
  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column align="center" label="书名" width="350">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>书名: {{ scope.row.bookName }}</p>
            <p>作者: {{ scope.row.author }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.bookName }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column align="center" label="出版日期" width="350">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.date }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click.prevent="handleEdit(scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click.prevent="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapState } from "vuex";

export default {
  name: "BookListView",
  methods: {
    handleDelete(row) {
      console.log(row);
      this.$store.commit("delBook", row.bookName);
    },
    handleEdit(row) {
      console.log(row);
      this.$store.commit("toEdit", row.bookName);
      this.$router.push("/editBook");
    }
  },
  computed: {
    ...mapState(["tableData"])
  }
};
</script>
